<template>
	<view style="background: #AEE2DA;min-height: 100vh;" class="Afont"
		:style="{background:'url('+Imgbase+'/new_goodday_bgc3.png)','background-size':'100%',}">
		<view class="padding-top-50 padding-left-40">
			<image class="w-80 h-80" :src="Imgbase + '/new_goodlx_img1.png'" mode="aspectFit" @click="back">
			</image>
		</view>
		<!-- :style="[{height:TabCur==0?'320rpx':'0rpx'}]" -->
		<view class="padding-top-310 overhid flex Afont margin-auto flex-center font-40">
			<view class="w-150">
				已签到
			</view>
			<view
				class="scoity-center-day radius-22 text-center padding-left-25 padding-right-10 padding-bottom-10 font-70">
				{{day}}
			</view>
			<view class="w-150 padding-left-20">
				天
			</view>
		</view>

		<!-- 立即签到 -->
		<view class="text-center padding-top-140">
			<image @click="dosign()" class="w-285 h-80" :src="Imgbase + '/new_goodday_img1.png'" mode="aspectFit">
			</image>
		</view>

		<view class="padding-top-270">
			<scroll-view scroll-y class="w100 h-340" scroll-with-animation style="overflow: hidden;"
				@scrolltolower="onbottom()">

				<view class="h-200 padding-top-50 w-570 margin-auto margin-top-25 padding-left-30 padding-right-30" v-for="(item,index) in scorelist" :key="index"
					:style="{background:'url('+Imgbase+'/app_sign_c_middle2.png)','background-size':'100% 100%',}">
					<view class="text-sm"
						style="padding-left: 20upx;padding-right: 20upx;color: #5c4228;">
						<view class="content fl text-ablack text-df">
							操作: {{item.memo}}
						</view>
						<view class="action fr text-df" :class="[item.money > 0?'text-green':'text-red']">
							<text v-show="item.money > 0">+</text>{{item.money}}
						</view>
					</view>
					<view style="clear: both;"></view>
					<view class="text-sm"
						style="padding-top: 0upx;padding-left: 20upx;padding-right: 20upx;color: #5c4228;">
						<view class="content fl text-ablack text-df">
							变更前:{{item.before}}
						</view>
						<view class="action fl text-ablack text-df padding-left">
							变更后:{{item.after}}
						</view>
					</view>
					<view style="clear: both;"></view>
					<view class="text-sm text-grey"
						style="padding-top: 10upx;padding-left: 20upx;padding-right: 20upx;">
						<view class="content fl text-gray text-df">
							{{item.createtime_text}}
						</view>
					</view>
					<view style="clear: both;"></view>
					<view style="width: 100%;height: 20upx;"></view>
				</view>

			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Imgbase: getApp().globalData.Imgbase,
				day: '000',
				issigned: 0,
				scoreData: true,
				scorelist: [],
				scorepage: 1,
				scorecount: 0,
				mes: '',
				modalName: null,
				scroll: 0
			};
		},
		onShow() {
			this.issign()
			this.init()
			this.explain()
		},
		methods: {
			onbottom() {
				if (this.scoreData) {
					this.scorepage++;
					this.scoreList();
				}
			},
			back() {
				uni.navigateBack()
			},
			explain() {
				let _this = this;
				uni.request({
					url: _this.$globals.apibase + '/api/Index/explain',
					data: {
						id: 9
					},
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						_this.mes = res.data.data.desc;
					}
				});
			},
			ScrollSteps() {
				this.scroll = this.scroll == 9 ? 0 : this.scroll + 1
			},
			hideModal(e) {
				this.modalName = null
			},
			init() {
				this.scorelist = [];
				this.scorepage = 1;
				this.scorecount = 0;
				this.scoreData = true;
				this.scoreList();
			},
			scoreList() {
				let _this = this;
				uni.request({
					url: _this.$globals.apibase + '/api/Userways/scoreluckLog',
					data: {
						token: uni.getStorageSync('token'),
						page: _this.scorepage,
						type: 3
					},
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.data.code == '401') {
							uni.setStorageSync('token', '');
							_this.$uniApi.trylogin();
						}
						if (res.data.code == '1') {
							_this.scorecount = res.data.data.count;
							for (let i = 0; i < res.data.data.list.length; i++) {
								// res.data.data.list[i].mes = JSON.parse(res.data.data.list[i].data);
								_this.scorelist = _this.scorelist.concat(res.data.data.list[i])
							}
							if (_this.scorelist.length >= _this.scorecount) {
								_this.scoreData = false
							}
						}
						if (res.data.code == '0') {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
					}
				});
			},
			dosign() {
				let _this = this;
				if (_this.issigned == 1) {
					uni.showToast({
						icon: 'none',
						title: '您今日已签到!'
					});
					return;
				}
				uni.request({
					url: _this.$globals.apibase + '/api/Usersys/postSign',
					data: {
						token: uni.getStorageSync('token'),
					},
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.data.code == '401') {
							uni.setStorageSync('token', '');
							_this.$uniApi.trylogin();
						}
						if (res.data.code == '1') {
							uni.showToast({
								icon: 'success',
								title: res.data.msg,
								duration: 3000,
							});
							_this.issigned = 1;
							uni.removeStorageSync('signed');
							_this.issign();
							_this.init()
						}
						if (res.data.code == '0') {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
					}
				});
			},
			issign() {
				let _this = this;
				var signed = uni.getStorageSync('signed').split("|");
				var need = 0;
				if (signed == '') {
					need = 1;
				} else {
					if (signed[1] < parseInt(new Date().getTime() / 1000)) {
						need = 1;
					}
					_this.day = signed[0];
					_this.issigned = signed[2];
					_this.scroll = _this.day % 7 - 1;
				}
				if (need == 1) {
					uni.request({
						url: _this.$globals.apibase + '/api/Usersys/isSign',
						data: {
							token: uni.getStorageSync('token'),
						},
						method: 'POST',
						header: {
							'content-type': 'application/json'
						},
						success: (res) => {
							if (res.data.code == '401') {
								uni.setStorageSync('token', '');
								_this.$uniApi.trylogin();
							}
							if (res.data.code == '1') {
								_this.issigned = res.data.data.state;
								var day1 = parseInt(parseInt(res.data.data.duration) / 100);
								var day2 = parseInt(parseInt(res.data.data.duration - day1 * 100) / 10);
								var day3 = parseInt(parseInt(res.data.data.duration - day1 * 100 - day2 * 10));
								_this.day = day1 + '' + day2 + '' + day3;
								var signmes = day1 + '' + day2 + '' + day3 + '|' + (new Date(new Date()
										.toLocaleDateString()).getTime() / 1000 + 60 * 60 * 24) + '|' + res
									.data.data.state;
								uni.setStorageSync('signed', signmes);
								_this.scroll = _this.day % 7 - 1;
							}
						}
					});
				}
			},
		}
		
	}
</script>
<style lang="less" scoped>
	.jiitem {
		float: left;
		margin-right: 20rpx;
		margin-bottom: 22rpx;
		position: relative;

		.opc {
			position: absolute;
			z-index: 10;
			background-color: rgba(0, 0, 0, .4);
			top: 2.5%;
			left: 2.5%;
			width: 95%;
			height: 95%;
		}

		.opc1 {
			position: absolute;
			z-index: 10;
			background-color: rgba(0, 0, 0, .4);
			top: 2.5%;
			left: 2%;
			width: 96%;
			height: 95%;
		}

		.zin {
			position: relative;
			z-index: 11;
		}
	}

	.jiitem:nth-child(4) {
		margin-right: 0;
	}

	.jiitem:nth-child(7) {
		margin-right: 0;
	}

	.scoity-center-day {
		color: #f9a24b;
		letter-spacing: 12px;
		background-color: rgba(255, 255, 255, .8);
	}

	.scoity-center-qiandao {
		margin-top: 60rpx;
	}

	.scoity-center-qiandao-text {
		font-size: 32rpx;
		text-decoration: underline;
		color: #FFFFFF;
		text-align: center;

	}
</style>